home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CICA Windows Explosion!
/
The CICA Windows Explosion! - Disc 2.iso
/
programr
/
wtj201.zip
/
KIYOOKA.ZIP
/
HEAPTEST.WMC
< prev
next >
Wrap
Text File
|
1992-10-23
|
14KB
|
473 lines
//Filename: HEAPTEST.WMC
//"HEAPTEST" Generated by WindowsMAKER Professional
//Author: Gen Kiyooka
//
// This file is maintained by WindowsMAKER Professional.
// As you make changes in your application using WindowsMAKER Professional
// this file is automatically updated therefore you never need to modify
// this file. Don't add code here.
// This file contains the default functions for: drawing bitmaps and icons,
// creating and registering the main window, handling the main menu.
// If you wish to replace any of these functions do so in the .C file.
// For more information see the section "How Code is Generated" in the
// documentation.
//*************************************************************
// GLOBAL VARIABLES
//*************************************************************
HBRUSH hMBrush = 0; // Handle to brush for main window
HINSTANCE hInst = 0; // Handle to instance.
HWND MainhWnd= 0; // Handle to main window.
HWND hClient = 0; // Handle to window in client area.
FARPROC lpClient= 0L; // Function for window in client area.
//*************************************************************
// PROCESSES KEYBOARD ACCELERATORS
// AND MODELESS DIALOG BOX KEY INPUT
//*************************************************************
BOOL BLDKeyTranslation(MSG *pMsg)
{
// Translate keystrokes so client area works as a dialog box
if (hClient && IsDialogMessage(hClient,pMsg))
return TRUE;
return FALSE; // No special key input
}
//*************************************************************
// CUSTOM MESSAGE PROCESSING FOR MAIN WINDOW
//*************************************************************
LONG FAR PASCAL BLDDefWindowProc(HWND hWnd, UINT message, UINT wParam, LONG lParam )
{
switch (message)
{
case WM_NCLBUTTONDOWN:
return BLD_WM_NCLBUTTONDOWNMsg(hWnd,message,wParam,lParam);
break;
case WM_CREATE:
MainhWnd=hWnd;
BLD_MainWinControlsClFunc(hWnd,message,wParam,lParam);
break;
case WM_SETFOCUS:
if (IsWindow(hClient))
SetFocus(hClient);
break;
case WM_NCDESTROY:
if (hMBrush)
{
SetClassWord(hWnd,GCW_HBRBACKGROUND,
(WORD)GetStockObject(WHITE_BRUSH));
DeleteObject(hMBrush);
hMBrush=0;
}
break;
default:
// Pass on message for default processing by Windows
return DefWindowProc(hWnd, message, wParam, lParam);
}
return FALSE; // Returns FALSE if not processed by Windows
}
//*************************************************************
// PROCESSES ALL MENU ITEM SELECTIONS
//*************************************************************
BOOL BLDMenuCommand(HWND hWnd, UINT message, UINT wParam, LONG lParam )
{
switch( LOWORD(wParam) )
{
// Processing of linked menu items in menu: HEAPTEST
default:
return FALSE; // Not processed by this function.
}
return TRUE; // Processed by this function.
}
//*************************************************************
// FUNCTIONS FOR INITIALIZATION AND EXIT OF APPLICATION
//*************************************************************
BOOL BLDInitApplication(HANDLE hInst, HANDLE hPrev, int *pCmdShow, LPSTR lpCmd)
{
// No initialization necessary
return TRUE;
}
// Registers the class for the main window
BOOL BLDRegisterClass( HANDLE hInstance )
{
WNDCLASS WndClass;
hMBrush=0;
WndClass.style = 0;
WndClass.lpfnWndProc = BLDMainWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = "HEAPTEST";
return RegisterClass(&WndClass);
}
HWND BLDCreateWindow( HANDLE hInstance ) // Creates the main window
{
HWND hWnd; // window handle
int coordinate[4]; // Coordinates of main window
coordinate[0]=CW_USEDEFAULT;
coordinate[1]=0;
coordinate[2]=CW_USEDEFAULT;
coordinate[3]=0;
hWnd = CreateWindow("HEAPTEST", // window class registered earlier
"Heap API Tester", // window caption
WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX, // window style
coordinate[0], // x position
coordinate[1], // y position
coordinate[2], // width
coordinate[3], // height
0, // parent handle
0, // menu or child ID
hInstance, // instance
(LPSTR)NULL); // additional info
return hWnd;
}
// Called just before entering message loop
BOOL BLDInitMainMenu(HWND hWnd)
{
// No initialization necessary
return TRUE;
}
BOOL BLDExitApplication() // Called just before exit of application
{
return TRUE;
}
//********************************************************
// ERROR MESSAGE HANDLING (Definitions can be overruled.)
//********************************************************
#ifndef ERRORCAPTION
#define ERRORCAPTION "Heap API Tester"
#endif
#ifndef LOADERROR
#define LOADERROR "Cannot load string."
#endif
int BLDDisplayMessage(HWND hWnd, unsigned uMsg, char *pContext, int iType)
{
int i, j;
char Message[200+1];
if (uMsg)
{
if (!LoadString(hInst,uMsg,Message,200))
{
MessageBox(hWnd,LOADERROR,ERRORCAPTION, MB_OK|MB_SYSTEMMODAL|MB_ICONHAND);
return FALSE;
}
}
else
Message[0]=0;
if (pContext)
{
i = lstrlen(Message);
j = lstrlen(pContext);
if (i + j + 1 <= 200)
{
lstrcat(Message, " ");
lstrcat(Message, pContext);
}
}
return MessageBox(hWnd,Message,ERRORCAPTION,iType);
}
//*************************************************************
// FUNCTIONS FOR DRAWING GRAPHIC BUTTONS
//*************************************************************
BOOL BLDDrawIcon(LPDRAWITEMSTRUCT lpDrawItem, char *pIconName)
{
HICON hIcon;
hIcon = LoadIcon(hInst,pIconName);
if (!hIcon)
{
BLDDisplayMessage(GetActiveWindow(),BLD_CannotLoadIcon,pIconName, MB_OK | MB_ICONASTERISK);
return FALSE;
}
SetMapMode(lpDrawItem->hDC,MM_TEXT);
return DrawIcon(lpDrawItem->hDC,0,0,hIcon);
}
BOOL BLDDrawBitmap(LPDRAWITEMSTRUCT lpDrawItem, char *pBitmapName, BOOL bStretch)
{
HBITMAP hBitmap;
HDC hMemDC;
BITMAP Bitmap;
int iRaster;
iRaster = GetDeviceCaps(lpDrawItem->hDC,RASTERCAPS);
if ((iRaster&RC_BITBLT)!=RC_BITBLT)
return FALSE; // Device cannot display bitmap
hBitmap = LoadBitmap(hInst,pBitmapName);
if (!hBitmap)
{
BLDDisplayMessage(GetActiveWindow(),BLD_CannotLoadBitmap,pBitmapName,
MB_OK | MB_ICONASTERISK);
return FALSE;
}
if (!GetObject(hBitmap,sizeof(BITMAP),(LPSTR)&Bitmap))
{
DeleteObject(hBitmap);
return FALSE;
}
hMemDC = CreateCompatibleDC(lpDrawItem->hDC);
if (!hMemDC)
{
DeleteObject(hBitmap);
return FALSE;
}
if (!SelectObject(hMemDC,hBitmap))
{
DeleteDC(hMemDC);
DeleteObject(hBitmap);
return FALSE;
}
if (bStretch)
{
StretchBlt(lpDrawItem->hDC,
lpDrawItem->rcItem.left,
lpDrawItem->rcItem.top,
lpDrawItem->rcItem.right-lpDrawItem->rcItem.left,
lpDrawItem->rcItem.bottom-lpDrawItem->rcItem.top,
hMemDC,
0,
0,
Bitmap.bmWidth,
Bitmap.bmHeight,
SRCCOPY);
}
else
{
BitBlt(lpDrawItem->hDC,
lpDrawItem->rcItem.left,
lpDrawItem->rcItem.top,
lpDrawItem->rcItem.right-lpDrawItem->rcItem.left,
lpDrawItem->rcItem.bottom-lpDrawItem->rcItem.top,
hMemDC,
0,
0,
SRCCOPY);
}
DeleteDC(hMemDC);
DeleteObject(hBitmap);
return TRUE;
}
//*************************************************************
// FUNCTION FOR CREATING CONTROLS IN MAIN WINDOW
//*************************************************************
// Startup procedure for window in client area
HWND BLDCreateClientControls(char *pTemplateName, FARPROC lpNew)
{
RECT rClient,rMain,rDialog;
int dxDialog,dyDialog,dyExtra,dtXold,dtYold;
HANDLE hRes,hMem;
LPBLD_DLGTEMPLATE lpDlg;
unsigned long styleold,style;
HWND hNew;
if (!IsWindow(MainhWnd))
return 0;
if (IsZoomed(MainhWnd))
ShowWindow(MainhWnd,SW_RESTORE);
if (IsWindow(hClient))
DestroyWindow(hClient); // Destroy Previous window in client area
// Get access to data structure of dialog box containing layout of controls
hRes=FindResource(hInst,(LPSTR)pTemplateName,RT_DIALOG);
if (!hRes)
return 0;
hMem=LoadResource(hInst,hRes);
if (!hMem)
return 0;
lpDlg=(LPBLD_DLGTEMPLATE)LockResource(hMem);
if (!lpDlg)
return 0;
// Change dialog box data structure so it can be used as a window in client area
styleold = lpDlg->dtStyle;
style = lpDlg->dtStyle&(CLIENTSTRIP);
lpDlg->dtStyle = lpDlg->dtStyle^style;
lpDlg->dtStyle = lpDlg->dtStyle | WS_CHILD | WS_CLIPSIBLINGS;
dtXold = lpDlg->dtX;
dtYold = lpDlg->dtY;
lpDlg->dtX = 0;
lpDlg->dtY = 0;
hNew = CreateDialogIndirect(hInst,(LPSTR)lpDlg, MainhWnd,lpNew);
if (!hNew)
return 0;
// Restore dialog box data structure.
lpDlg->dtStyle = styleold;
lpDlg->dtX = dtXold;
lpDlg->dtY = dtYold;
UnlockResource(hMem);
FreeResource(hMem);
// Move and size window in client area and main window
GetClientRect(MainhWnd,&rClient);
GetWindowRect(MainhWnd,&rMain);
GetWindowRect(hNew,&rDialog);
dxDialog=(rDialog.right-rDialog.left)-(rClient.right-rClient.left);
dyDialog=(rDialog.bottom-rDialog.top)-(rClient.bottom-rClient.top);
BLDMoveWindow(MainhWnd,rMain.left,rMain.top,
(rMain.right-rMain.left)+dxDialog,
(rMain.bottom-rMain.top)+dyDialog,
TRUE);
MoveWindow(hNew,0,0,
(rDialog.right-rDialog.left),
(rDialog.bottom-rDialog.top),
TRUE);
GetClientRect(MainhWnd,&rClient);
// Compensate size if menu bar is more than one line.
if ((rDialog.bottom-rDialog.top)>(rClient.bottom-rClient.top))
{
dyExtra=(rDialog.bottom-rDialog.top)-(rClient.bottom-rClient.top);
BLDMoveWindow(MainhWnd,rMain.left,rMain.top,
(rMain.right-rMain.left)+dxDialog,
(rMain.bottom-rMain.top)+dyDialog+dyExtra,
TRUE);
}
ShowWindow(hNew,SW_SHOW);
hClient=hNew;
lpClient=lpNew;
return hClient;
}
// Ensure that window is within screen.
void BLDMoveWindow(HWND hWnd, int x, int y,
int nWidth, int nHeight, BOOL bRepaint)
{
int xMax,yMax,xNew,yNew;
xMax = GetSystemMetrics(SM_CXSCREEN);
yMax = GetSystemMetrics(SM_CYSCREEN);
if ((nWidth<=xMax)&&(x+nWidth>xMax))
xNew=xMax-nWidth;
else
xNew=x;
if ((nHeight<=yMax)&&(y+nHeight>yMax))
yNew=yMax-nHeight;
else
yNew=y;
MoveWindow(hWnd,xNew,yNew,nWidth,nHeight,bRepaint);
return;
}
//*************************************************************
// FUNCTION FOR SWITCHING MENU SET
//*************************************************************
BOOL BLDSwitchMenu(HWND hWnd, char *pTemplateName)
{
HMENU hMenu1,hMenu;
DWORD style;
style = GetWindowLong(hWnd,GWL_STYLE);
if((style & WS_CHILD) == WS_CHILD) // Called from control in main window?
{
hWnd=GetParent(hWnd);
if (!hWnd)
return FALSE;
style = GetWindowLong(hWnd,GWL_STYLE);
if((style & WS_CHILD) == WS_CHILD) // No menu in a WS_CHILD window.
return FALSE;
}
if((style & WS_CAPTION) != WS_CAPTION) // No menu if no caption.
return FALSE;
hMenu1 = GetMenu(hWnd);
hMenu = LoadMenu(hInst,pTemplateName);
if (!hMenu)
{
BLDDisplayMessage(hWnd,BLD_CannotLoadMenu,pTemplateName,
MB_OK | MB_ICONASTERISK);
return FALSE;
}
if (!SetMenu(hWnd,hMenu))
return FALSE;
if (hMenu1)
DestroyMenu(hMenu1);
DrawMenuBar(hWnd);
return TRUE;
}